/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.bussines.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Vogel
 */
@Entity
@Table(name = "comunas")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Comunas.findAll", query = "SELECT c FROM Comunas c"),
    @NamedQuery(name = "Comunas.findByCUTComuna", query = "SELECT c FROM Comunas c WHERE c.cUTComuna = :cUTComuna"),
    @NamedQuery(name = "Comunas.findByNomComu", query = "SELECT c FROM Comunas c WHERE c.nomComu = :nomComu")})
public class Comunas implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "CUT_Comuna")
    private Integer cUTComuna;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "Nom_Comu")
    private String nomComu;
    @JoinColumn(name = "CUT_Provincia", referencedColumnName = "CUT_Provincia")
    @ManyToOne(optional = false)
    private Provincias cUTProvincia;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cUTComuna")
    private Collection<Clientes> clientesCollection;
    @OneToMany(mappedBy = "cUTComuna")
    private Collection<Sucursales> sucursalesCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cUTComuna")
    private Collection<Empleados> empleadosCollection;

    public Comunas() {
    }

    public Comunas(Integer cUTComuna) {
        this.cUTComuna = cUTComuna;
    }

    public Comunas(Integer cUTComuna, String nomComu) {
        this.cUTComuna = cUTComuna;
        this.nomComu = nomComu;
    }

    public Integer getCUTComuna() {
        return cUTComuna;
    }

    public void setCUTComuna(Integer cUTComuna) {
        this.cUTComuna = cUTComuna;
    }

    public String getNomComu() {
        return nomComu;
    }

    public void setNomComu(String nomComu) {
        this.nomComu = nomComu;
    }

    public Provincias getCUTProvincia() {
        return cUTProvincia;
    }

    public void setCUTProvincia(Provincias cUTProvincia) {
        this.cUTProvincia = cUTProvincia;
    }

    @XmlTransient
    public Collection<Clientes> getClientesCollection() {
        return clientesCollection;
    }

    public void setClientesCollection(Collection<Clientes> clientesCollection) {
        this.clientesCollection = clientesCollection;
    }

    @XmlTransient
    public Collection<Sucursales> getSucursalesCollection() {
        return sucursalesCollection;
    }

    public void setSucursalesCollection(Collection<Sucursales> sucursalesCollection) {
        this.sucursalesCollection = sucursalesCollection;
    }

    @XmlTransient
    public Collection<Empleados> getEmpleadosCollection() {
        return empleadosCollection;
    }

    public void setEmpleadosCollection(Collection<Empleados> empleadosCollection) {
        this.empleadosCollection = empleadosCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cUTComuna != null ? cUTComuna.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comunas)) {
            return false;
        }
        Comunas other = (Comunas) object;
        if ((this.cUTComuna == null && other.cUTComuna != null) || (this.cUTComuna != null && !this.cUTComuna.equals(other.cUTComuna))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cl.bussines.entities.Comunas[ cUTComuna=" + cUTComuna + " ]";
    }
    
}
